package com.yanqu.road.server.manger.assistant;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.ActivityRewardResult;
import com.yanqu.road.entity.activity.advertisement.AdvertisementUserData;
import com.yanqu.road.entity.activity.advertisement.config.AdvertisementConfig;
import com.yanqu.road.entity.activity.mall.MallActivityInfo;
import com.yanqu.road.entity.assistant.UserAssistantZsSetData;
import com.yanqu.road.entity.beautyescort.EscortBeautyData;
import com.yanqu.road.entity.beautyescort.EscortBeautyDispatch;
import com.yanqu.road.entity.config.battle.BattleResult;
import com.yanqu.road.entity.config.beauty.BeautyTrystResult;
import com.yanqu.road.entity.config.goods.BuyGoodsResult;
import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.entity.config.player.UserDecorationInfoResult;
import com.yanqu.road.entity.config.skill.SkillInfo;
import com.yanqu.road.entity.config.skill.SkillUpgradeInfo;
import com.yanqu.road.entity.config.zhaoshang.ZsProjectInfo;
import com.yanqu.road.entity.enums.*;
import com.yanqu.road.entity.enums.activity.advertisement.eAdvertisementSystemId;
import com.yanqu.road.entity.estatewar.EstateBuildingInfo;
import com.yanqu.road.entity.grandchild.GrandChildData;
import com.yanqu.road.entity.grandchild.SchoolSiteData;
import com.yanqu.road.entity.player.*;
import com.yanqu.road.entity.relatives.RelativesGift;
import com.yanqu.road.entity.relatives.RelativesInfo;
import com.yanqu.road.entity.task.TaskInfo;
import com.yanqu.road.entity.task.UserTaskActive;
import com.yanqu.road.entity.task.UserTaskData;
import com.yanqu.road.entity.tradewar.UserTradeWarBuilding;
import com.yanqu.road.entity.union.UnionConstructResult;
import com.yanqu.road.entity.union.UnionInfo;
import com.yanqu.road.logic.bussiness.player.UserBeautyBussiness;
import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.logic.pb.HousePb;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.activity.AdvertisementProto;
import com.yanqu.road.pb.activity.CardProto;
import com.yanqu.road.pb.assistant.AssistantProto;
import com.yanqu.road.pb.beauty.BeautyProto;
import com.yanqu.road.pb.charitable.CharitableProto;
import com.yanqu.road.pb.child.ChildProto;
import com.yanqu.road.pb.clinic.ClinicProto;
import com.yanqu.road.pb.decoration.DecorationProto;
import com.yanqu.road.pb.drugstore.DrugStoreProto;
import com.yanqu.road.pb.estatewar.EstateWarProto;
import com.yanqu.road.pb.grandchild.GrandChildProto;
import com.yanqu.road.pb.manor.FishPondProto;
import com.yanqu.road.pb.manor.ManorProto;
import com.yanqu.road.pb.npc.NpcEventProto;
import com.yanqu.road.pb.tradewar.team.TradeWarTeamProto;
import com.yanqu.road.pb.wineshop.WineShopProto;
import com.yanqu.road.pb.zhaoshang.ZhaoShangProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.TempMgr;
import com.yanqu.road.server.cmd.decoration.MammonWorshipCmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ActivityMallModule;
import com.yanqu.road.server.gameplayer.module.activity.ActivityModule;
import com.yanqu.road.server.gameplayer.module.activity.advertisement.AdvertisementActivityModule;
import com.yanqu.road.server.gameplayer.module.assistant.AssistantModule;
import com.yanqu.road.server.gameplayer.module.beautyescort.BeautyEscortModule;
import com.yanqu.road.server.gameplayer.module.charitable.CharitableDoTenTimeResult;
import com.yanqu.road.server.gameplayer.module.charitable.CharitableModule;
import com.yanqu.road.server.gameplayer.module.clinic.ClinicModule;
import com.yanqu.road.server.gameplayer.module.drugstore.DrugStoreModule;
import com.yanqu.road.server.gameplayer.module.grandson.GrandChildModule;
import com.yanqu.road.server.gameplayer.module.kowloon.KowloonModule;
import com.yanqu.road.server.gameplayer.module.mall.MallModule;
import com.yanqu.road.server.gameplayer.module.manor.ManorFishPondModel;
import com.yanqu.road.server.gameplayer.module.manor.ManorHarvestModel;
import com.yanqu.road.server.gameplayer.module.manor.ManorModule;
import com.yanqu.road.server.gameplayer.module.musicroom.MusicRoomModule;
import com.yanqu.road.server.gameplayer.module.npc.NpcEventModule;
import com.yanqu.road.server.gameplayer.module.patrons.PatronsModule;
import com.yanqu.road.server.gameplayer.module.player.*;
import com.yanqu.road.server.gameplayer.module.relatives.RelativesModule;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.gameplayer.module.union.cross.CrossUnionModule;
import com.yanqu.road.server.gameplayer.module.wineshop.WineShopModule;
import com.yanqu.road.server.gameplayer.module.zhaoshang.ZsModule;
import com.yanqu.road.server.logic.task.BaseTaskData;
import com.yanqu.road.server.manger.ConfigMgr;
import com.yanqu.road.server.manger.VipMgr;
import com.yanqu.road.server.manger.activity.MallActivityMgr;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.server.manger.activity.advertisement.AdvertisementActivityMgr;
import com.yanqu.road.server.manger.activity.curio.CurioMgr;
import com.yanqu.road.server.manger.beautyescort.BeautyEscortMgr;
import com.yanqu.road.server.manger.config.*;
import com.yanqu.road.server.manger.log.LogMgr;
import com.yanqu.road.server.manger.maidian.entity.BuyShopItem;
import com.yanqu.road.server.manger.maidian.resource.BuyItemLog;
import com.yanqu.road.server.manger.palace.PalaceActivity;
import com.yanqu.road.server.manger.palace.PalaceActivityMgr;
import com.yanqu.road.server.manger.player.EstateWarMgr;
import com.yanqu.road.server.manger.player.TradeWarMgr;
import com.yanqu.road.server.manger.player.UserMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.manger.relatives.RelativesMgr;
import com.yanqu.road.server.manger.union.CrossUnionMgr;
import com.yanqu.road.server.manger.zhaoshang.ZsConfigMgr;
import com.yanqu.road.server.manger.zhaoshang.ZsMgr;
import com.yanqu.road.server.pb.BeautyPb;
import com.yanqu.road.server.pb.CharitablePb;
import com.yanqu.road.server.pb.GrandChildPb;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;
import com.yanqu.road.utils.string.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.math.BigInteger;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

/**
 * @Description
 * @Author cwq
 * @Data 2021/8/2 18:19
 */
public class AssistantMgr extends TempMgr {

    public static final Logger logger = LogManager.getLogger(AssistantMgr.class.getName());

    @Override
    public boolean init() throws Exception {
        return false;
    }

    @Override
    public boolean reloadConfig() throws Exception {
        return false;
    }

    @Override
    public boolean reloadData() throws Exception {
        return false;
    }

    @Override
    public boolean stop() {
        return false;
    }

//    /**
//     * 是否包含皇城操作
//     */
//    public static boolean includeWorshipAction(long bit) {
//        return BitUtil.get(bit, AssistantProto.AssistantActionType.ESTATE_WAR_WORSHIP.getNumber());
//    }
//
//    /**
//     * 是否包含押镖操作
//     */
//    public static boolean includeEscortAction(long bit) {
//        return BitUtil.get(bit, AssistantProto.AssistantActionType.BEAUTY_ESCORT_DART.getNumber());
//    }
//
//    /**
//     * 是否包含商会操作
//     */
//    public static boolean includeUnionAction(long bit) {
//        return BitUtil.get(bit, AssistantProto.AssistantActionType.UNION_CONSTRUCTION_SIMPLE.getNumber())
//                || BitUtil.get(bit, AssistantProto.AssistantActionType.UNION_CONSTRUCTION_MIDDLE.getNumber())
//                || BitUtil.get(bit, AssistantProto.AssistantActionType.UNION_CONSTRUCTION_HIGH.getNumber())
//                || BitUtil.get(bit, AssistantProto.AssistantActionType.UNION_PARERGON.getNumber())
//                || BitUtil.get(bit, AssistantProto.AssistantActionType.UNION_RECEIVE_BOX.getNumber());
//    }

    /**
     * 是否包含皇城操作
     */
    public static boolean includeWorshipAction(List<Integer> operateList) {
        return operateList.contains(AssistantProto.AssistantActionType.ESTATE_WAR_WORSHIP.getNumber());
    }

    /**
     * 是否包含押镖操作
     */
    public static boolean includeEscortAction(List<Integer> operateList) {
        return operateList.contains(AssistantProto.AssistantActionType.BEAUTY_ESCORT_DART.getNumber());
    }

    /**
     * 是否包含招商操作
     */
    public static boolean includeZsAction(List<Integer> operateList) {
        return operateList.contains(AssistantProto.AssistantActionType.ZS_OPEN.getNumber());
    }

    /**
     * 是否包含商会操作
     */
    public static boolean includeUnionAction(List<Integer> operateList) {

        return operateList.contains(AssistantProto.AssistantActionType.UNION_CONSTRUCTION_SIMPLE.getNumber())
                || operateList.contains(AssistantProto.AssistantActionType.UNION_CONSTRUCTION_MIDDLE.getNumber())
                || operateList.contains(AssistantProto.AssistantActionType.UNION_CONSTRUCTION_HIGH.getNumber())
                || operateList.contains(AssistantProto.AssistantActionType.UNION_PARERGON.getNumber())
                || operateList.contains(AssistantProto.AssistantActionType.UNION_RECEIVE_BOX.getNumber());
    }


    /**
     * 皇城操作
     */
    public static int worshipAction(GamePlayer player, AssistantProto.AssistantActionReqMsg.Builder reqMsg, AssistantProto.AssistantActionRespMsg.Builder respMsg) {
        AssistantProto.AssistantCrossActionReqMsg.Builder crossMsg = AssistantProto.AssistantCrossActionReqMsg.newBuilder();
        PalaceActivity palaceActivity = PalaceActivityMgr.getInTimePalaceActivity();
        if (null != palaceActivity) {
            crossMsg.setActivityId(palaceActivity.getPalaceActivityId());
            crossMsg.setAssistantActionReqMsg(reqMsg);
            crossMsg.setAssistantActionRespMsg(respMsg);
            player.sendPacket(Protocol.C_PALACE_ASSISTANT_ACTION, crossMsg);
            return 0;
        } else {
            // 不在皇城活动时间
            return GameErrorCode.E_PALACE_ACTIVITY_NO_FOUND;
        }
    }

    /**
     * 押镖操作
     */
    public static int escortAction(GamePlayer player, AssistantProto.AssistantActionReqMsg.Builder reqMsg, AssistantProto.AssistantActionRespMsg.Builder respMsg) {
        AssistantProto.AssistantCrossActionReqMsg.Builder crossMsg = AssistantProto.AssistantCrossActionReqMsg.newBuilder();
        crossMsg.setAssistantActionReqMsg(reqMsg);
        crossMsg.setAssistantActionRespMsg(respMsg);
        // 判断是否有商会
        if (StringUtils.isNullOrEmpty(player.getUserInfo().getUnionUid())) {
            return GameErrorCode.E_UNION_NO_JOIN_UNION;
        }
        // 商会等级限制
        UnionInfo unionInfo = CrossUnionMgr.getUnionInfo(player.getUserInfo().getUnionUid());
        if (UnionConfigMgr.getUnionLv(unionInfo.getExperience()) < GameConfig.ESCORT_OPEN_UNION_LEVEL) {
            return GameErrorCode.E_BEAUTY_ESCORT_UNION_LEVEL_NO_ENOUGH;
        }
        // 时间限制
        if (!ConfigMgr.isEscortTimeInDay()) {
            return GameErrorCode.E_BEAUTY_ESCORT_NO_IN_ESCORT_TIME;
        }
        // 普通押镖
        BeautyModule beautyModule = player.getModule(BeautyModule.class);
        BeautyEscortModule beautyEscortModule = player.getModule(BeautyEscortModule.class);
        if (!beautyEscortModule.systemOpen()) {
            return GameErrorCode.E_BEAUTY_ESCORT_SYSTEM_NO_OPEN;
        }
        List<EscortBeautyDispatch> beautyDispatchList = new ArrayList<>();
        int escortFreeTimes = beautyEscortModule.getEscortFreeTimes();
        // 获取所有有免费次数的美女
        for (Map.Entry<Integer, UserBeauty> beautyEntry : beautyModule.getUserBeautyMap().entrySet()) {
            UserBeauty userBeauty = beautyEntry.getValue();
            EscortBeautyData escortBeautyData = beautyEscortModule.getByBeautyId(beautyEntry.getKey());
            if (escortBeautyData.getEscortTimes() < escortFreeTimes) {
                // 添加到可派遣列表
                escortBeautyData.setEscortTimes(escortBeautyData.getEscortTimes() + 1);
                EscortBeautyDispatch dispatch = new EscortBeautyDispatch();
                dispatch.setBeautyId(beautyEntry.getKey());
                dispatch.setGlamour(userBeauty.getTotalGlamour());
                dispatch.setLeftDispatchTime(escortFreeTimes - escortBeautyData.getEscortTimes());
                beautyDispatchList.add(dispatch);
            }
        }
        // 添加派遣日志
        String dispatchIds = beautyDispatchList.stream().map(beautyDispatch -> String.valueOf(beautyDispatch.getBeautyId())).collect(Collectors.joining(","));
        logger.info("小玉助手自动押镖,玩家: {}, 派遣美女Id列表: {}", player.getUserId(), dispatchIds);
        crossMsg.addAllBeauty(BeautyEscortMgr.parseBeautyDispatchBuilderList(beautyDispatchList));
        UserBaseInfo userBaseInfo = UserMgr.getUserBaseInfo(player.getUserId(), GameServer.getInstance().getServerId());
        if (userBaseInfo != null) {
            crossMsg.setUserInfo(PlayerBasePb.parsePlayerBaseTempMsg(userBaseInfo));
        }
        player.sendPacket(Protocol.C_ESCORT_ASSISTANT_ACTION, crossMsg);
        return 0;
    }

    /**
     * 商会操作
     */
    public static boolean unionAction(GamePlayer player, AssistantProto.AssistantActionReqMsg.Builder reqMsg, AssistantProto.AssistantActionRespMsg.Builder respMsg) {
        AssistantProto.AssistantCrossActionReqMsg.Builder crossMsg = AssistantProto.AssistantCrossActionReqMsg.newBuilder();
        boolean needCross = false;
        List<Integer> operateEnumList = reqMsg.getOperateEnumList();
        for (AssistantProto.AssistantActionType item : AssistantProto.AssistantActionType.values()) {
//            if (!BitUtil.get(reqMsg.getBit(), item.getNumber())) {
//                continue;
//            }
            if (!operateEnumList.contains(item.getNumber())) {
                continue;
            }

            switch (item) {
                case UNION_CONSTRUCTION_SIMPLE:
                    // 商会初级建设
                    UnionConstructResult result = getUnionConstructResult(player, respMsg, crossMsg, item, 1);
                    if (result.getRet() == 0) {
                        needCross = true;
                    }
                    break;
                case UNION_CONSTRUCTION_MIDDLE:
                    // 商会中级建设
                    UnionConstructResult result2 = getUnionConstructResult(player, respMsg, crossMsg, item, 2);
                    if (result2.getRet() == 0) {
                        needCross = true;
                    }
                    break;
                case UNION_CONSTRUCTION_HIGH:
                    // 商会高级建设
                    UnionConstructResult result3 = getUnionConstructResult(player, respMsg, crossMsg, item, 3);
                    if (result3.getRet() == 0) {
                        needCross = true;
                    }
                    break;
                case UNION_PARERGON:
                    // 商会经营
                    crossMsg.setOneKeyOperate(true);
                    needCross = true;
                    break;
                case UNION_RECEIVE_BOX:
                    // 商会领取宝箱
                    crossMsg.setOneKeyReceiveActive(true);
                    needCross = true;
                    break;
            }
        }
        crossMsg.setAssistantActionReqMsg(reqMsg);
        crossMsg.setAssistantActionRespMsg(respMsg);
        if (needCross) {
            player.sendPacket(Protocol.C_UNION_ASSISTANT_ACTION, crossMsg);
        }
        return needCross;
    }

    /**
     * 小助理操作
     *
     * @param player
     * @param reqMsg
     */
    public static AssistantProto.AssistantActionRespMsg.Builder action(GamePlayer player, AssistantProto.AssistantActionReqMsg.Builder reqMsg, AssistantProto.AssistantActionRespMsg.Builder respMsg) {
        long startTime = System.currentTimeMillis();
        //拿出操作的类型
        List<Integer> operateEnumList = reqMsg.getOperateEnumList();
        //遍历枚举
        for (AssistantProto.AssistantActionType item : AssistantProto.AssistantActionType.values()) {
//            if (!BitUtil.get(reqMsg.getBit(), item.getNumber())) {
//                continue;
//            }
            //判断是否包含该类型
            if (!operateEnumList.contains(item.getNumber())) {
                continue;
            }
            // 执行该类型操作
            switch (item) {
                case PRAY:
                    // 祈福 MammonWorshipCmd
                    DecorationProto.MammonWorshipRespMsg.Builder mammonWorshipRespMsg = MammonWorshipCmd.mammonWorship(player);
                    respMsg.setMammonWorshipRespMsg(mammonWorshipRespMsg);
                    break;
                case ESTATE_WAR_WORSHIP:
                    // 乔迁膜拜 (2个)
                    for (EstateBuildingInfo buildingInfo : EstateWarConfigMgr.getEstateBuildingInfoMap().values()) {
                        if (EstateWarConfigMgr.getEstateBuildingCanWorship(buildingInfo.getType())) {
                            EstateWarProto.EstateWarWorshipRespMsg.Builder estateWarWorshipRespMsg = EstateWarMgr.estateWarWorship(player, buildingInfo.getType());
                            AssistantProto.AssistantEstateWarWorshipResult.Builder result = AssistantProto.AssistantEstateWarWorshipResult.newBuilder();
                            result.setType(buildingInfo.getType());
                            result.setEstateWarWorshipRespMsg(estateWarWorshipRespMsg);
                            respMsg.addEstateWarWorshipResultList(result);
                        }
                    }
                    break;
                case CHARITABLE_WORK_WORSHIP:
                    // 行善
                    int charitableDoTimes = Math.min(reqMsg.getCharitableTimes(), GameConfig.ASSISTANT_CHARITABLE_MAX_TIMES);
                    UserCharitable userCharitable = player.getModule(CharitableModule.class).getUserCharitable();
                    if (userCharitable == null) {
                        charitableDoTimes = 0;
                    } else {
                        //服务端初始次数是 1 .。。
                        charitableDoTimes = charitableDoTimes - userCharitable.getTodayCharitableTimes() + 1;
                    }
                    CharitableDoTenTimeResult charitableDoTenTimeResult = player.getModule(CharitableModule.class).doCharitableTen(charitableDoTimes);
                    CharitableProto.CharitableTenDoResp.Builder charitableTenDoResp = CharitablePb.getCharitableTenDoResp(charitableDoTenTimeResult);
                    respMsg.setCharitableTenDoResp(charitableTenDoResp);

                    //反正就是要同步
                    player.getModule(CharitableModule.class).initSystem();
                    break;

                case TRAVEL:
                    // 游历
                    AssistantProto.AssistantTravelGoRespMsg.Builder travelGoRespMsg = TravelMgr.oneKeyTravel(player, reqMsg.getId());
                    respMsg.setTravelGoRespMsg(travelGoRespMsg);
                    break;
                case MONOR:
                    doMonor(respMsg, player);
                    break;
                case CLINIC:
                    doClinic(respMsg, player);
                    break;
                case WINESHOP:
                    doWineShop(respMsg, player);
                    break;
                case BANCK_BAR:
                    doBankBar(respMsg, player);
                    break;
                case RELATIVES_GIVE_GIFT:
                    // 自动世交赠礼
                    doRelativesGift(respMsg, player);
                    break;
                case TRADE_WAR_BUILDING_GET_REWARD:
                    //税所自动领取收益
                    doTradeWarBuildingGetReward(respMsg, player);
                    break;
                case SHOP_BUY:
                    //小助理购买
                    respMsg.setAssistantShopBuyRespMsg(player.getModule(AssistantModule.class).assistantBuy());
                    break;
                case FISHPOND_ENERGY_REWARD:
                    // 地龙领取
                    doGetFishpondEnergyReward(respMsg, player);
                    break;
                case GRAND_CHILD_TRAIN:
                    // 孙子培养
                    doGrandChildTrain(respMsg, player);
                    break;
                case GRAND_CHILD_ENTER_SCHOOL:
                    // 孙子入学
                    doGrandChildEnterSchool(reqMsg, respMsg, player);
                    break;
                case GET_TITLE_REWARD:
                    // 获取身份奖励
                    respMsg.setTitleRewardRespMsg(player.getModule(PlayerModule.class).getTitleReward());
                    break;
                case CHARITABLE_UPGRADE:
                    // 自动提升行善地点等级
                    doCharitablePositionUpgrade(respMsg, player);
                    break;
                case DRUGSTORE:
                    doDrugStore(respMsg, player);
                    break;
                case TRADE_WAR_FAST_FIGHT:
                    doFastFight(respMsg, player);
                    break;
                case MONTH_CARD_REWARD:
                    //月卡特权领取
                    respMsg.setMonthCardRespMsg(doMonthCardReward(player));
                    break;
                case YEAR_CARD_REWARD:
                    //年卡特权领取
                    respMsg.setYearCardRespMsg(doYearCardReward(player));
                    break;
                case MUSIC_ROOM_GET_REWARD:
                    respMsg.setMusicRoomGetBuildingRewardRespMsg(player.getModule(MusicRoomModule.class).getBuildingAmountReward());
                    break;
                case BEAUTY_FAVOR:
                    boolean hundredTime = false;
                    if (reqMsg.hasBeautyFavorHundred()){
                        hundredTime = reqMsg.getBeautyFavorHundred();
                    }

                    // 美女一键传唤
                    doBeautyFavor(respMsg, player,hundredTime);
                    break;
                case CHILD_TRAIN:
                    // 子嗣一键培养
                    boolean openComprehend=false;
                    if (reqMsg.hasOpenComprehend()){
                        openComprehend = reqMsg.getOpenComprehend();
                    }
                    doChildTrain(respMsg, player,openComprehend);
                    break;
                case KOW_LOON_REWARD:
                    // 九龙城寨奖励
                    doKowLoon(respMsg, player);
                    break;
                case DAILY_TASK:
                    // 日常任务一键领取
                    doDailyTaskAward(respMsg, player);
                    break;
                case ACT_LIMIT_TASK:
                    //限时任务一键领取
                    doActLimitTaskAward(respMsg, player);
                    break;
                case AD_SHOP_BUY:
                    // 广告商店一键购买
                    doAdShopBuyAward(respMsg, player);
                    break;
                case AD_LOTTERY_REWARD:
                    doAssistantWatchAdAward(respMsg, player,eAdvertisementSystemId.lottery.getValue(),0);
                    break;
                case AD_TRAVEL_REWARD:
                    int beautyId = 0;
                    if (reqMsg.hasId()){
                        beautyId = reqMsg.getId();
                    }
                    doAssistantWatchAdAward(respMsg,player,eAdvertisementSystemId.travel.getValue(),beautyId);
                    break;
                case AD_NPC_REWARD:
                    doAssistantWatchAdAward(respMsg,player,eAdvertisementSystemId.buildingNpc.getValue(),0);
                    break;
                case AD_EARN_SPEED_REWARD:
                    doAssistantWatchAdAward(respMsg,player,eAdvertisementSystemId.addEarnSpeed.getValue(),0);
                    break;
                case AD_WA_SHE_DAILY_REWARD:
                    doAssistantWatchAdAward(respMsg, player, eAdvertisementSystemId.washe.getValue(), 0);
                    break;
                case AD_CONDITION_REWARD:
                    player.getModule(AdvertisementActivityModule.class).getConditionReward(respMsg);
                    break;
                case AD_DAY_LOGIN:
                    doAssistantWatchAdAward(respMsg, player, eAdvertisementSystemId.Login.getValue(), 0);
                    break;
                case TRADE_EVENT:
                    NpcEventProto.NpcAutoTradeRespMsg.Builder autoTradeBuilder = NpcEventProto.NpcAutoTradeRespMsg.newBuilder();
                    int ret = player.getModule(NpcEventModule.class).npcTradeEventStock();
                    if (ret == 0 || ret == GameErrorCode.E_BAG_ITEM_NO_ENOUGH) {
                        autoTradeBuilder.setStock(NpcEventProto.NpcTradeStockRespMsg.newBuilder().setRet(ret));
                    } else {
                        String npcTradeNowReward = player.getModule(NpcEventModule.class).getNpcTradeNowReward();
                        ret = player.getModule(NpcEventModule.class).getNpcTradeReward();
                        autoTradeBuilder.setGetReward(NpcEventProto.GetNpcTradeRewardRespMsg.newBuilder().setRet(ret));
                        if (ret == 0) {
                            autoTradeBuilder.setReward(npcTradeNowReward);
                            //领奖完再贸易一次
                            ret = player.getModule(NpcEventModule.class).npcTradeEventStock();
                            autoTradeBuilder.setStock(NpcEventProto.NpcTradeStockRespMsg.newBuilder().setRet(ret));
                        }
                    }
                    respMsg.setNpcAutoTradeRespMsg(autoTradeBuilder);
                    break;
                default:
                    break;
            }
        }
        respMsg.setRet(0);
        respMsg.setBit(reqMsg.getBit());
        respMsg.addAllOperateEnum(operateEnumList);
        long endTime = System.currentTimeMillis();
        logger.info("执行小助理耗时：{},bit:{},userId:{}", endTime - startTime, operateEnumList, player.getUserId());
        player.sendPacket(Protocol.U_ASSISTANT_ACTION, respMsg);


        //同步学位信息
        GrandChildProto.SyncSchoolSiteMsg.Builder syncSiteMsg = GrandChildProto.SyncSchoolSiteMsg.newBuilder();
        for (List<SchoolSiteData> dataList :  player.getModule(GrandChildModule.class).getSchoolSiteMap().values()) {
            for (SchoolSiteData data : new ArrayList<>(dataList)) {
                GrandChildProto.SchoolSiteMsg.Builder msg = GrandChildProto.SchoolSiteMsg.newBuilder();
                msg.setType(data.getSchoolType());
                msg.setPos(data.getPos());
                if (!StringUtils.isNullOrEmpty(data.getChildId())) {
                    GrandChildData childData = player.getModule(GrandChildModule.class).getGrandChildDataMap().get(data.getChildId());
                    if (childData != null) {
                        GrandChildProto.GrandChildMsg.Builder childMsg = GrandChildPb.parseGrandChildMsg(childData);
                        msg.setGrandChild(childMsg);
                    }
                }
                syncSiteMsg.addData(msg);
            }
        }
        player.sendPacket(ClientProtocol.U_SYNC_GRAND_CHILD_SCHOOL_DATA, syncSiteMsg);

        return respMsg;
    }

    private static void doFastFight(AssistantProto.AssistantActionRespMsg.Builder respMsg, GamePlayer player) {
        TradeWarTeamProto.TradeWarTeamBattleRespMsg.Builder battleRespMsg = TradeWarTeamProto.TradeWarTeamBattleRespMsg.newBuilder();
        int ret = 0;

        if(player.getTitleId() < GameConfig.TRADE_WAR_TEAM_OPEN_LEVEL &&
                VipMgr.getVipLv(player.getUserInfo().getVipExp()) < GameConfig.TRADE_WAR_TEAM_OPEN_VIP){
            if(player.getTitleId() < GameConfig.TRADE_WAR_TEAM_OPEN_LEVEL) {
                ret = GameErrorCode.E_TITLE_LEVEL_NO_ENOUGH;
            }else {
                ret = GameErrorCode.E_VIP_LEVEL_NO_ENOUGH;
            }
        }
        TradeWarTeamModule tradeWarTeamModule = player.getModule(TradeWarTeamModule.class);
        if(null == tradeWarTeamModule.getUserTradeWarTeam()){//系统未解锁
            ret = GameErrorCode.E_SYSTEM_NO_OPEN;
        }
        if(tradeWarTeamModule.getTeamPatronsCount() <= 0){
            ret = GameErrorCode.E_TRADE_WAR_TEAM_PATRONS_COUNT_NO_ENOUGH;
        }
        if(ret != 0){
            battleRespMsg.setRet(ret);
            respMsg.setTradeWarFast(battleRespMsg);
            return;
        }
        List<BattleResult> resultList = player.getModule(TradeWarTeamModule.class).tradeWarTeamBattle();
        for (BattleResult battleResult : resultList) {
            TradeWarMgr.buildWarTeamBattleTemp(battleRespMsg, battleResult);
        }
        battleRespMsg.setRet(0);
        respMsg.setTradeWarFast(battleRespMsg);
    }

    private static UnionConstructResult getUnionConstructResult(GamePlayer player, AssistantProto.AssistantActionRespMsg.Builder builder, AssistantProto.AssistantCrossActionReqMsg.Builder crossReq,
                                                                AssistantProto.AssistantActionType item, int constructType) {
        UnionConstructResult result2 = player.getModule(CrossUnionModule.class).preConstructUnion(constructType);
        if(result2.getRet() == 0){
            AssistantProto.AssistantUnionCrossBuildTemp.Builder temp = AssistantProto.AssistantUnionCrossBuildTemp.newBuilder();
            temp.setConstructionType(constructType);
            if(result2.getConsume() != null){
                temp.setConsume(PropertyHelper.parsePropertyToString(result2.getConsume()));
            }
            crossReq.addBuild(temp);
        }else {
            AssistantProto.AssistantCommonResult.Builder unionConstructResultBuilder1 = builderAssistantCommonResult(result2, item.getNumber());
            builder.addCommonResultList(unionConstructResultBuilder1);
        }
        return result2;
    }

    /**
     * 税所领取收益
     * @param builder
     * @param player
     */
    public static void doTradeWarBuildingGetReward(AssistantProto.AssistantActionRespMsg.Builder builder, GamePlayer player) {
        AssistantProto.AssistantTradeWarBuildingGetRewardRespMsg.Builder getRewardRespMsg = AssistantProto.AssistantTradeWarBuildingGetRewardRespMsg.newBuilder();
        TradeWarBuildingModule tradeWarBuildingModule = player.getModule(TradeWarBuildingModule.class);
        UserTradeWarBuilding userTradeWarBuilding = tradeWarBuildingModule.getUserTradeWarBuilding(eTradeWarBuildingType.TaxOffice.getValue());
        if (null == userTradeWarBuilding) {//商战建筑未解锁
            getRewardRespMsg.setRet(GameErrorCode.E_TRADE_WAR_BUILDING_IS_LOCK);
            builder.setTradeWarBuildingGetRewardRespMsg(getRewardRespMsg);
            return;
        }
        long nowTime = System.currentTimeMillis() / 1000;
        if (nowTime - userTradeWarBuilding.getLastGetTime() < GameConfig.TRADE_WAR_BANK_GET_SILVER_MIN_TIME) {//领取太频繁
            getRewardRespMsg.setRet(GameErrorCode.E_TRADE_WAR_BANK_GET_SILVER_TIME_OFTEN);
            builder.setTradeWarBuildingGetRewardRespMsg(getRewardRespMsg);
            return;
        }
        Property reward = tradeWarBuildingModule.getBuildingReward(eTradeWarBuildingType.TaxOffice.getValue(), nowTime, false);
        getRewardRespMsg.setSilverReward(PropertyHelper.parsePropertyToString(reward));
        getRewardRespMsg.setRet(0);
        builder.setTradeWarBuildingGetRewardRespMsg(getRewardRespMsg);
    }

    /**
     * 最大每日领取亲家体力赠礼（玩家离线时使用）
     */
    public static Map<Long, Integer> getMaxDayReceiveTravelPower(List<Long> userIdList){
        Map<Long, Integer> userMap = new ConcurrentHashMap<>();
        Map<Long, Map<Integer, UserBeauty>> beautyMap = UserBeautyBussiness.getUserBeautyMap(userIdList);
        for (Map.Entry<Long, Map<Integer, UserBeauty>> entry : beautyMap.entrySet()) {
            int addition = SkillMgr.getIdentitySkillAddition(entry.getValue(), eSkillType.TravelPowerGiftLimitAdd.getValue(), 0);
            userMap.put(entry.getKey(), GameConfig.RELATIVES_DAY_RECEIVE_NUM + addition);
        }
        return userMap;
    }

    /**
     * 世交赠礼
     * @param builder
     * @param player
     */
    public static void doRelativesGift(AssistantProto.AssistantActionRespMsg.Builder builder, GamePlayer player) {
        AssistantProto.AssistantRelativesGiveGiftRespMsg.Builder giftRespMsg = AssistantProto.AssistantRelativesGiveGiftRespMsg.newBuilder();
        giftRespMsg.setRet(0);
        //今日已赠礼次数
        int giveTimes = player.getModule(RelativesModule.class).getGiftTimes(true);
        //玩家每日最大赠礼次数
        int maxGiveTimes = RelativesMgr.getMaxDayGiveTravelPower(player);
        int canGiveTimes = maxGiveTimes - giveTimes;
        int timesTmp = canGiveTimes;
        if (canGiveTimes > 0) {
            Map<Long, RelativesInfo> relativesMap = player.getModule(RelativesModule.class).getRelativesMap();

            List<Long> needLoadDbList = new ArrayList<>();  //需要查表的玩家id列表
            List<GamePlayer> onlinePlayerList = new ArrayList<>();  //在线的玩家列表
            List<Long> crossUserIdList = new ArrayList<>();

            for (Long relativesId : relativesMap.keySet()) { //玩家的亲家都遍历出来 不在线的就一起去查库 不要一个个去查库了
                RelativesInfo relativesInfo = player.getModule(RelativesModule.class).getRelativesInfo(relativesId);
                if (relativesInfo == null || relativesInfo.getStatus() == 0) {
                    continue;
                }
                //跨服亲家
                long relativesServerId = RelativesMgr.getUserServerId(relativesId);
                if(GameServer.getInstance().getServerId() != relativesServerId){
                    crossUserIdList.add(relativesId);
                    continue;
                }
                GamePlayer relativesPlayer = GamePlayerMgr.getOnlinePlayer(relativesId);
                if (relativesPlayer == null) {
                    needLoadDbList.add(relativesId);
                } else {
                    onlinePlayerList.add(relativesPlayer);
                }
            }
            //查玩家能接收的最大数量
            Map<Long, Integer> receiveTravelPowerMap = new ConcurrentHashMap<>();
            if (needLoadDbList.size() > 0) {
                receiveTravelPowerMap = getMaxDayReceiveTravelPower(needLoadDbList);
                //把离线玩家的赠礼数据load到内存里面 执行一次
                RelativesMgr.loadRelativesGiftFromDb(needLoadDbList);
            }
            if (onlinePlayerList.size() > 0) {
                for (GamePlayer gamePlayer : onlinePlayerList) {
                    int maxTimes = RelativesMgr.getMaxDayReceiveTravelPower(gamePlayer);
                    receiveTravelPowerMap.put(gamePlayer.getUserId(), maxTimes);
                }
            }

            //遍历赠礼
            for (Map.Entry<Long, Integer> entry : receiveTravelPowerMap.entrySet()) {
                if (canGiveTimes <= 0) {
                    break;
                }
                //获取亲家的今日受赠数量
                int times = RelativesMgr.getDayGiftNum(entry.getKey(), false, false);
                //已经最大了 不能再收
                if (times >= entry.getValue()) {
                    continue;
                }

                //已经送过了
                RelativesGift gift = player.getModule(RelativesModule.class).getGiveMap().get(entry.getKey());
                if (gift != null) {
                    continue;
                }
                gift = RelativesMgr.createRelativesGift(player.getUserId(), entry.getKey());
                player.getModule(RelativesModule.class).getGiveMap().put(entry.getKey(), gift);

                //同步对方收礼列表
                GamePlayer onlinePlayer = GamePlayerMgr.getOnlinePlayer(entry.getKey());
                if (onlinePlayer != null) {
                    onlinePlayer.getModule(RelativesModule.class).syncGiveGiftMsg(gift);
                }
                canGiveTimes--;
            }

            //跨服送礼
            for (Long crossUserId : crossUserIdList) {
                if (canGiveTimes <= 0) {
                    break;
                }
                if(player.getModule(RelativesModule.class).sendCrossGift(crossUserId, RelativesMgr.getUserServerId(crossUserId)) == 0) {
                    canGiveTimes--;
                }
            }
        }
        giftRespMsg.setGiveTimes(timesTmp - canGiveTimes);
        giftRespMsg.setRemainGiveTimes(canGiveTimes);

        //今日已领取赠礼次数
        int getTimes = player.getModule(RelativesModule.class).getGiftTimes(false);
        int maxGetTimes = RelativesMgr.getMaxDayReceiveTravelPower(player);
        int count = 0;
        int canGetTimes = maxGetTimes - getTimes;
        if (getTimes < maxGetTimes) {
            Map<Long, RelativesInfo> relativesMap = player.getModule(RelativesModule.class).getRelativesMap();
            for (Long relativesId : relativesMap.keySet()) {
                if (canGetTimes == count) {
                    break;
                }
                RelativesInfo relativesInfo = player.getModule(RelativesModule.class).getRelativesInfo(relativesId);
                if (relativesInfo == null || relativesInfo.getStatus() == 0) {
                    continue;
                }
                int ret = player.getModule(RelativesModule.class).receiveGift(relativesId);
                if (ret == 0) {
                    count ++;
                }
            }
            // 加道具
            Property property = PropertyHelper.parseStringToProperty(GameConfig.RELATIVES_GIFT_CONFIG);
            Property newProperty = new Property();
            int finalCount = count;
            property.getGoods().forEach((k, v)->{
                newProperty.addProperty(k, v.multiply(BigInteger.valueOf(finalCount)));
            });
            player.getModule(CurrencyModule.class).addCurrency(newProperty, eLogMoneyType.Relatives, eLogMoneyType.RelativesGift);
            giftRespMsg.setReward(PropertyHelper.parsePropertyToString(newProperty));
        }
        giftRespMsg.setGetTimes(count);
        giftRespMsg.setRemainGetTimes(canGetTimes - count);

        if (getTimes >= maxGetTimes && giveTimes >= maxGiveTimes) {
            giftRespMsg.setRet(GameErrorCode.E_RELATIVES_GIVE_OVER);
        }
        builder.setRelativesGiveGiftRespMsg(giftRespMsg);
        // 同步赠礼列表
        player.getModule(RelativesModule.class).syncGiftList();
    }

    /**
     * 庄园收获
     *
     * @param builder
     * @param player
     */
    public static void doMonor(AssistantProto.AssistantActionRespMsg.Builder builder, GamePlayer player) {
        ManorHarvestModel harvestModel = player.getModule(ManorModule.class).getHarvestModel();
        if(harvestModel == null){
            //还未解锁
            ManorProto.ManorHarvestRespMsg.Builder respMsg = ManorProto.ManorHarvestRespMsg.newBuilder();
            respMsg.setRet(GameErrorCode.E_BAG_MANOR_SYSTEM_LOCK);
            builder.setManorHarvestRespMsg(respMsg);
            return;
        }
        ManorProto.ManorHarvestRespMsg.Builder harvestMsg = harvestModel.harvestMsg();
        builder.setManorHarvestRespMsg(harvestMsg);
    }

    /**
     * 钱庄
     *
     * @param builder
     * @param player
     */
    public static void doBankBar(AssistantProto.AssistantActionRespMsg.Builder builder, GamePlayer player) {
        // 先执行撤回  再执行派遣
        int ret = 0;
        HouseModule houseModule = player.getModule(HouseModule.class);
        Map<String, Property> recallPatrons = houseModule.assistantRecallPatrons();
        AssistantProto.AssistantHouseDispatchPatronsRespMsg.Builder respMsg = AssistantProto.AssistantHouseDispatchPatronsRespMsg.newBuilder();
        if (!SystemOpenMgr.systemOpen(player, eSystemId.HouseBank.getValue())) {
            respMsg.setRet(GameErrorCode.E_SYSTEM_NO_OPEN);
            builder.setHouseDispatchPatronsRespMsg(respMsg);
            return;
        }
        respMsg.setRet(ret);
        for (String posAndPatronsId : recallPatrons.keySet()) {
            List<Integer> intList = StringUtils.stringToIntegerList(posAndPatronsId, "-");
            Property reward = recallPatrons.get(posAndPatronsId);
            respMsg.addRewardList(HousePb.parseHouseBarRewardTempMsg(intList.get(0), intList.get(1), reward));
        }

        List<UserHouseBar> emptyBarList = new ArrayList<>();
        Map<Integer, UserHouseBar> userHouseBarMap = houseModule.getUserHouseBarMap();
        List<UserPatrons> userPatronsList = player.getModule(PatronsModule.class).getUserPatronsList();
        Set<Integer> allPatronsId = new HashSet<>();
        for (UserPatrons patrons : userPatronsList) {
            allPatronsId.add(patrons.getPatronsId());
        }
        for (UserHouseBar bar : userHouseBarMap.values()) {
            if (bar.getPatronsId() == 0) {
                emptyBarList.add(bar);
            } else {
                allPatronsId.remove(bar.getPatronsId());
            }
        }

        userPatronsList = new ArrayList<>();
        for (Integer patronsId : allPatronsId) {
            userPatronsList.add(player.getModule(PatronsModule.class).getUserPatrons(patronsId));
        }

        // 排序
        userPatronsList.sort((o1, o2) -> o2.getAbility().compareTo(o1.getAbility()));

        List<Integer> dispatchPatronId = new ArrayList<>();
        UserHouseBarDispatch userHouseBarDispatch = houseModule.getUserHouseBarDispatch();
        if (userHouseBarDispatch != null) {
            dispatchPatronId = userHouseBarDispatch.getDispatchPatronsList();
        }


        // 财源广进技能是否满级或者所有可以消耗百业经验升级的技能是否均已满级,满级的放到后面
        List<UserPatrons> dispatchPatrons1 = new ArrayList<>();
        List<UserPatrons> dispatchPatrons2 = new ArrayList<>();
        for (UserPatrons userPatrons : userPatronsList) {
            if (!player.getModule(PatronsModule.class).checkSkillMaxLevel(userPatrons.getPatronsId(), GameConfig.PATRONS_CHOUSUAN_EXP_ID, GameConfig.PATRONS_BAIYE_EXP_ID)) {
                dispatchPatrons1.add(userPatrons);
            } else {
                dispatchPatrons2.add(userPatrons);
            }
        }

        userPatronsList = new ArrayList<>();
        userPatronsList.addAll(dispatchPatrons1);
        userPatronsList.addAll(dispatchPatrons2);


        // 派遣设置名单的门客放到前面,其他未派遣的放到后面
        dispatchPatrons1 = new ArrayList<>();
        dispatchPatrons2 = new ArrayList<>();
        for (UserPatrons userPatrons : userPatronsList) {
            if (dispatchPatronId.contains(userPatrons.getPatronsId())) {
                dispatchPatrons1.add(userPatrons);
            } else {
                dispatchPatrons2.add(userPatrons);
            }
        }

        userPatronsList = new ArrayList<>();
        userPatronsList.addAll(dispatchPatrons1);
        userPatronsList.addAll(dispatchPatrons2);

        int num = 0;
        for (UserHouseBar bar : emptyBarList) {
            if (userPatronsList.size() == 0) {
                break;
            }
            UserPatrons userPatrons = userPatronsList.remove(0);
            bar.setPatronsId(userPatrons.getPatronsId());
            bar.setDispatchTime(System.currentTimeMillis());
            num++;
        }
        if (num == 0) {
            if (emptyBarList.size() == 0) {
                ret = 1;
            } else if (userPatronsList.size() == 0) {
                ret = 2;
            }
        }
        respMsg.setRet(ret);
        respMsg.setNum(num);
        builder.setHouseDispatchPatronsRespMsg(respMsg);
        houseModule.syncUserHouseBank();
    }

    private static void doDrugStore(AssistantProto.AssistantActionRespMsg.Builder builder, GamePlayer player) {
        DrugStoreProto.DrugReceptPatientRespMsg.Builder respMsg = DrugStoreProto.DrugReceptPatientRespMsg.newBuilder();
        if (SystemOpenMgr.systemOpen(player, eSystemId.DrugStore.getValue())) {
            int ret = player.getModule(DrugStoreModule.class).receivePatientOneKey(respMsg, true);
            respMsg.setRet(ret);
        }else {
            respMsg.setRet(GameErrorCode.E_SYSTEM_NO_OPEN);
        }
        builder.setDrugRespMsg(respMsg);
    }

    public static void doClinic(AssistantProto.AssistantActionRespMsg.Builder builder, GamePlayer player) {
        ClinicProto.ReceptPatientRespMsg.Builder respMsg = ClinicProto.ReceptPatientRespMsg.newBuilder();
        if (SystemOpenMgr.systemOpen(player, eSystemId.Clinic.getValue())) {
            player.getModule(ClinicModule.class).offlineCure();
            player.getModule(ClinicModule.class).oneKeyReceptPatient(respMsg, true);
        } else {
            respMsg.setRet(GameErrorCode.E_SYSTEM_NO_OPEN);
        }
        builder.setReceptPatientRespMsg(respMsg);
    }

    public static void doWineShop(AssistantProto.AssistantActionRespMsg.Builder builder, GamePlayer player) {

        WineShopProto.WineShopReceptionRespMsg.Builder respMsg = WineShopProto.WineShopReceptionRespMsg.newBuilder();
        int ret = 0;
        if (SystemOpenMgr.systemOpen(player, eSystemId.WineShop.getValue())) {
            player.getModule(WineShopModule.class).offLineReception();
            ret = player.getModule(WineShopModule.class).oneKeyReceptionBeauty(respMsg, true);
        } else {
            ret = GameErrorCode.E_SYSTEM_NO_OPEN;
        }
        respMsg.setRet(ret);
        builder.setWineShopReceptionRespMsg(respMsg);
    }


    /**
     * 是否保护跨服1的操作
     *
     * @param bit
     * @return
     */
    public static boolean includeCross1Action(long bit) {
        return false;
    }

    public static AssistantProto.AssistantCommonResult.Builder builderAssistantCommonResult(UnionConstructResult result, int actionType) {
        AssistantProto.AssistantCommonResult.Builder builder = AssistantProto.AssistantCommonResult.newBuilder();
        builder.setRet(result.getRet());
        builder.setId(actionType);
        if (result.getRet() == 0) {
            if (result.getReward() != null) {
                builder.setReward(PropertyHelper.parsePropertyToString(result.getReward()));
            }
            if (result.getConsume() != null) {
                builder.setConsume(PropertyHelper.parsePropertyToString(result.getConsume()));
            }
        }
        return builder;
    }

    public static void clearUnionMallSet(long userId) {
        GamePlayer player = GamePlayerMgr.getOnlinePlayer(userId);
        if (player != null) {
            player.getModule(AssistantModule.class).clearUnionMallSet();
        }
    }
    public static AssistantProto.AssistantCommonResult.Builder builderAssistantCommonResult(int ret, String reward, String consume, int actionType) {
        AssistantProto.AssistantCommonResult.Builder builder = AssistantProto.AssistantCommonResult.newBuilder();
        builder.setRet(ret);
        builder.setId(actionType);
        if (ret == 0) {
            if (!StringUtils.isNullOrEmpty(reward)) {
                builder.setReward(reward);
            }
            if (!StringUtils.isNullOrEmpty(consume)) {
                builder.setConsume(consume);
            }
        }
        return builder;
    }

    /**
     * 自动领取地龙
     * @param builder
     * @param player
     */
    public static void doGetFishpondEnergyReward(AssistantProto.AssistantActionRespMsg.Builder builder, GamePlayer player) {
        FishPondProto.GetFishPondEnergyRespMsg.Builder respMsg = FishPondProto.GetFishPondEnergyRespMsg.newBuilder();
        ManorFishPondModel manorFishPondModel = player.getModule(ManorModule.class).getManorFishPondModel();
        if (manorFishPondModel == null || manorFishPondModel.getFishPondData() == null || manorFishPondModel.getFishPondData().getFishPondLv() == 0) {
            respMsg.setRet(GameErrorCode.E_FISH_POND_IS_LOCK);
            respMsg.setRecoveryTime(0);
        } else {
            if (manorFishPondModel.getFishPondData().getFishPondScore() <= 0) {
                respMsg.setRet(GameErrorCode.E_FISH_POND_ENERGY_NOT_ENOUGH);
                respMsg.setRecoveryTime(0);
            } else {
                manorFishPondModel.getEnergy(respMsg);
            }
        }
        builder.setGetFishPondEnergyRespMsg(respMsg);
    }


    /**
     * 处理自动升级行善地点
     * @param builder
     * @param player
     */
    public static void doCharitablePositionUpgrade(AssistantProto.AssistantActionRespMsg.Builder builder, GamePlayer player) {
        AssistantProto.CharitablePositionUpgradeRespMsg.Builder upgradeRespMsg = AssistantProto.CharitablePositionUpgradeRespMsg.newBuilder();
        // 获取行善技能列表
        Map<Integer, Map<Integer, UserCharitableSkill>> positionSkillMap = player.getModule(CharitableModule.class).getPositionSkillMap();
        // 获取行善地点列表
        Map<Integer, UserCharitablePosition> userCharitablePositionMap = player.getModule(CharitableModule.class).getUserCharitablePositionMap();
        for (Map.Entry<Integer, UserCharitablePosition> positionEntry : userCharitablePositionMap.entrySet()) {
            AssistantProto.CharitablePositionUpgradeTemp.Builder tempMsg = AssistantProto.CharitablePositionUpgradeTemp.newBuilder();
            UserCharitablePosition userCharitablePosition = positionEntry.getValue();
            if (userCharitablePosition == null) {
                continue;
            }
            for (Map.Entry<Integer, UserCharitableSkill> skillEntry : positionSkillMap.get(positionEntry.getKey()).entrySet()) {
                UserCharitableSkill userCharitableSkill = skillEntry.getValue();
                // 判断行善技能
                if (userCharitableSkill == null) {
                    continue;
                }
                // 判断技能配置
                SkillInfo skillInfo = SkillMgr.getSkillInfo(skillEntry.getKey());
                if (skillInfo == null) {
                    continue;
                }
                boolean isChange = false;
                int level = userCharitableSkill.getLevel();
                tempMsg.setOldLevel(level);
                // 可以升级则升级至上限
                while (true) {
                    // 判断升级配置
                    SkillUpgradeInfo nextUpgradeInfo = SkillMgr.getSkillUpgradeInfo(skillInfo.getUpgradeType(0), level + 1);
                    if (nextUpgradeInfo == null) {
                        break;
                    }
                    // 判断升级的消耗是否足够
                    SkillUpgradeInfo consume = SkillMgr.getSkillUpgradeInfo(skillInfo.getUpgradeType(0), level);
                    if (consume == null) {
                        break;
                    }
                    if (userCharitablePosition.getCharitableForUpgradeTimes() < consume.getConsumeCount()) {
                        break;
                    }
                    level++;
                    isChange = true;
                }
                if (isChange) {
                    // 修改等级
                    userCharitableSkill.setLevel(level);
                    tempMsg.setNewLevel(userCharitableSkill.getLevel());
                    tempMsg.setPositionId(userCharitableSkill.getPosition());
                    tempMsg.setSkillId(userCharitableSkill.getSkillId());
                    upgradeRespMsg.addUpgradeList(tempMsg);
                }
            }
        }
        builder.setCharitablePositionUpgradeRespMsg(upgradeRespMsg);
    }


    /**
     * 孙子培养
     * @param builder
     * @param player
     */
    private static void doGrandChildTrain(AssistantProto.AssistantActionRespMsg.Builder builder, GamePlayer player) {
        AssistantProto.AssistantGrandChildTrainRespMsg.Builder grandChildTrainRespMsg = AssistantProto.AssistantGrandChildTrainRespMsg.newBuilder();
        if (SystemOpenMgr.systemOpen(player, eSystemId.GrandChild.getValue())) {
            Map<Integer, List<SchoolSiteData>> schoolSiteMap = player.getModule(GrandChildModule.class).getSchoolSiteMap();
            for (List<SchoolSiteData> siteDataList : schoolSiteMap.values()) {
                GrandChildProto.SchoolTrainRespMsg.Builder resp = GrandChildProto.SchoolTrainRespMsg.newBuilder();
                if (siteDataList != null) {
                    for (SchoolSiteData schoolSiteData : siteDataList) {
                        if (StringUtils.isNullOrEmpty(schoolSiteData.getChildId())) {
                            continue;
                        }
                        player.getModule(GrandChildModule.class).doTrainResult(resp, schoolSiteData, 0);
                    }
                }
                grandChildTrainRespMsg.addAllTrain(resp.getResultList());
            }
            grandChildTrainRespMsg.setRet(0);
        } else {
            grandChildTrainRespMsg.setRet(GameErrorCode.E_SYSTEM_NO_OPEN);
        }
        builder.setAssistantGrandChildTrainRespMsg(grandChildTrainRespMsg);
    }

    /**
     * 孙子入学
     * @param reqMsg
     * @param builder
     * @param player
     */
    private static void doGrandChildEnterSchool(AssistantProto.AssistantActionReqMsg.Builder reqMsg, AssistantProto.AssistantActionRespMsg.Builder builder, GamePlayer player) {
        AssistantProto.AssistantGrandChildEnterSchoolRespMsg.Builder enterSchoolRespMsg = AssistantProto.AssistantGrandChildEnterSchoolRespMsg.newBuilder();
        if (SystemOpenMgr.systemOpen(player, eSystemId.GrandChild.getValue())) {
            //需要同步的孙子
            List<GrandChildData> syncGrandChildList = new ArrayList<>();
            //获取学校空学位MAP.K:学校类型，V:空学位
            Map<Integer, List<SchoolSiteData>> schoolEmptySiteMap = player.getModule(GrandChildModule.class).getSchoolEmptySiteMap();
            //遍历学校=>门客
            for (AssistantProto.AssistantGrandChildEnterSchoolItem grandChildEnterSchoolItem : reqMsg.getGrandChildEnterSchoolList()) {
                AssistantProto.AssistantGrandChildEnterSchoolItemMsg.Builder enterSchoolItem = AssistantProto.AssistantGrandChildEnterSchoolItemMsg.newBuilder();
                //门客ID
                int patronsId = grandChildEnterSchoolItem.getPatronsId();
                //学校类型
                int schoolType = grandChildEnterSchoolItem.getSchoolType();
                enterSchoolItem.setSchoolType(schoolType);
                //获取未入学的孙子，根据职业（学校类型）（按天资排序）
                List<GrandChildData> notStudyGrandChildList = player.getModule(GrandChildModule.class).getGrandChildByOccupation(schoolType);
                if (notStudyGrandChildList.isEmpty()) {
                    enterSchoolItem.setRet(GameErrorCode.E_GRAND_ENTER_SCHOOL_NOT_GRAND_CHILD);
                    enterSchoolRespMsg.addGrandChildEnterSchool(enterSchoolItem);
                    continue;
                }
                //判断是否有门客
                if (patronsId <= 0) {
                    enterSchoolItem.setRet(GameErrorCode.E_GRAND_ENTER_SCHOOL_NOT_SELECT_PATRONS);
                    enterSchoolRespMsg.addGrandChildEnterSchool(enterSchoolItem);
                    continue;
                }
                //是否有门客
                UserPatrons patrons = player.getModule(PatronsModule.class).getUserPatrons(patronsId);
                if (patrons == null) {
                    enterSchoolItem.setRet(GameErrorCode.E_PATRONS_NO_FOUND);
                    enterSchoolRespMsg.addGrandChildEnterSchool(enterSchoolItem);
                    continue;
                }
                //获取学校空学位
                List<SchoolSiteData> schoolEmptySiteDataList = schoolEmptySiteMap.get(schoolType);
                if (schoolEmptySiteDataList.isEmpty()) {
                    enterSchoolItem.setRet(GameErrorCode.E_GRAND_CHILD_SCHOOL_FULL);
                    enterSchoolRespMsg.addGrandChildEnterSchool(enterSchoolItem);
                    continue;
                }
                //需要入学的孙子IDS
                int emptySiteNum = schoolEmptySiteDataList.size();
                List<String> grandChildIdList = new ArrayList<>();
                for (GrandChildData grandChildData : notStudyGrandChildList) {
                    if (emptySiteNum <= 0) {
                        break;
                    }
                    grandChildIdList.add(grandChildData.getId());
                    syncGrandChildList.add(grandChildData);
                    emptySiteNum--;
                }
                //孙子进行入学操作,返回作为信息
                List<SchoolSiteData> newSchoolSiteDataList = player.getModule(GrandChildModule.class).doEnterSchool(schoolType, grandChildIdList, patronsId);
                //培养
                for (SchoolSiteData schoolSiteData : newSchoolSiteDataList) {
                    GrandChildProto.SchoolTrainRespMsg.Builder resp = GrandChildProto.SchoolTrainRespMsg.newBuilder();
                    //培养一次
                    player.getModule(GrandChildModule.class).doTrainResult(resp, schoolSiteData, 0);
                    resp.setRet(0);
                    player.sendPacket(ClientProtocol.U_GRAND_CHILD_TRAIN, resp);
                }
                enterSchoolItem.setRet(0);
                enterSchoolItem.setPatronsId(patronsId);
                enterSchoolItem.setGrandChildNum(newSchoolSiteDataList.size());
                enterSchoolRespMsg.addGrandChildEnterSchool(enterSchoolItem);
            }
            enterSchoolRespMsg.setRet(0);

            //同步一下孙子信息
            GrandChildProto.SyncGrandChildMsg.Builder syncGrandChildMsg = GrandChildProto.SyncGrandChildMsg.newBuilder();
            for (GrandChildData data : syncGrandChildList) {
                if (data.getLv() == 0) {
                    data.setLv(1);
                }
                GrandChildProto.GrandChildMsg.Builder msg = GrandChildPb.parseGrandChildMsg(data);
                syncGrandChildMsg.addData(msg);
            }
            player.sendPacket(ClientProtocol.U_SYNC_GRANDSON_DATA, syncGrandChildMsg);
        } else {
            enterSchoolRespMsg.setRet(GameErrorCode.E_SYSTEM_NO_OPEN);
        }
        builder.setGrandChildEnterSchoolRespMsg(enterSchoolRespMsg);
    }

    /**
     * 月卡特权领取奖励
     * @param player
     * @return
     */
    private static CardProto.PrivilegeCardRewardRespMsg.Builder doMonthCardReward(GamePlayer player) {
        CardProto.PrivilegeCardRewardRespMsg.Builder builder = CardProto.PrivilegeCardRewardRespMsg.newBuilder();
        builder.setRet(0);
        builder.setType(eCardType.MonthCard.getValue());
        if(!player.getModule(CardModule.class).isInCardTime(builder.getType())){
            builder.setRet(GameErrorCode.E_CARD_OVER_TIME);
            return builder;
        }
        if(player.getModule(CardModule.class).hasGetReward(builder.getType())){
            builder.setRet(GameErrorCode.E_CARD_HAS_GET_REWARD);
            return builder;
        }
        Property reward = player.getModule(CardModule.class).getReward(builder.getType());
        UserCard userCard = player.getModule(CardModule.class).getUserCard();
        if (userCard != null) {
            builder.setGetRewardTime(userCard.getGetMonthCardRewardTime());
        }
        if (reward != null) {
            builder.setReward(PropertyHelper.parsePropertyToString(reward));
        }
        return builder;
    }


    /**
     * 年卡特权领取奖励
     * @param player
     * @return
     */
    private static CardProto.PrivilegeCardRewardRespMsg.Builder doYearCardReward(GamePlayer player) {
        CardProto.PrivilegeCardRewardRespMsg.Builder builder = CardProto.PrivilegeCardRewardRespMsg.newBuilder();
        builder.setRet(0);
        builder.setType(eCardType.YearCard.getValue());
        if(!player.getModule(CardModule.class).isInCardTime(builder.getType())){
            builder.setRet(GameErrorCode.E_CARD_OVER_TIME);
            return builder;
        }
        if(player.getModule(CardModule.class).hasGetReward(builder.getType())){
            builder.setRet(GameErrorCode.E_CARD_HAS_GET_REWARD);
            return builder;
        }
        Property reward = player.getModule(CardModule.class).getReward(builder.getType());
        UserCard userCard = player.getModule(CardModule.class).getUserCard();
        if (userCard != null) {
            builder.setGetRewardTime(userCard.getGetYearCardRewardTime());
        }
        if (reward != null) {
            builder.setReward(PropertyHelper.parsePropertyToString(reward));
        }
        return builder;
    }

    /**
     * 一键传唤
     */
    private static void doBeautyFavor(AssistantProto.AssistantActionRespMsg.Builder builder, GamePlayer player,boolean hundredTime) {
        BeautyProto.BeautyTrystRespMsg.Builder respMsg = BeautyProto.BeautyTrystRespMsg.newBuilder();
        if (SystemOpenMgr.systemOpen(player, eSystemId.Beauty.getValue())) {
            if (hundredTime) {
                // 一键百次传唤
                BeautyTrystResult result = player.getModule(BeautyModule.class).beautyTryst(3, true);
                respMsg = BeautyPb.parseBeautyTrystRespMsg(result);
                builder.setBeautyFavorRespMsg(respMsg);
                return;
            }

            BeautyTrystResult result = player.getModule(BeautyModule.class).beautyTryst(2, true);
            respMsg = BeautyPb.parseBeautyTrystRespMsg(result);
        } else {
            respMsg.setRet(GameErrorCode.E_SYSTEM_NO_OPEN);
        }
        builder.setBeautyFavorRespMsg(respMsg);
    }


    /**
     * 一键子嗣培养
     */
    private static void doChildTrain(AssistantProto.AssistantActionRespMsg.Builder builder, GamePlayer player,boolean openComprehend) {
        AssistantProto.AssistantChildTrainRespMsg.Builder childTrainRespMsg = AssistantProto.AssistantChildTrainRespMsg.newBuilder();
        //如果没周卡 并且没有年卡的情况
        if(!player.getModule(CardModule.class).isOneKeyTrainChild() && !player.getModule(CardModule.class).isOneKeyTrainAllChild()){
            //并且身份 vip不足
            String[] arr = GameConfig.CHILDREN_ADVANCED_TRAIN_NEED_TITLE_LIMIT.split("\\|");
            int titleLimit = Integer.parseInt(arr[0]);
            int vipLimit = Integer.parseInt(arr[1]);
            if (player.getUserInfo().getTitleId() < titleLimit && VipMgr.getVipLv(player.getUserInfo().getVipExp()) < vipLimit) {
                ChildProto.ChildTrainRespMsg.Builder respMsg = ChildProto.ChildTrainRespMsg.newBuilder();
                respMsg.setRet(GameErrorCode.E_TITLE_LEVEL_NO_ENOUGH);
                return;
            }
        }


        if (SystemOpenMgr.systemOpen(player, eSystemId.Child.getValue())) {
            // 获取当前可培养的子嗣列表
            player.getModule(ChildModule.class).childAutoTrain(childTrainRespMsg, openComprehend);
            childTrainRespMsg.setRet(0);
        } else {
            childTrainRespMsg.setRet(GameErrorCode.E_SYSTEM_NO_OPEN);
        }

        builder.setAssistantChildTrainRespMsg(childTrainRespMsg);
    }

    /**
     * 领取九龙挂机收益
     */
    private static void doKowLoon(AssistantProto.AssistantActionRespMsg.Builder builder, GamePlayer player) {
        AssistantProto.AssistantKowLoonAwardRespMsg.Builder kowLoonAwardRespMsg = AssistantProto.AssistantKowLoonAwardRespMsg.newBuilder();
        if (SystemOpenMgr.systemOpen(player, eSystemId.Kowloon.getValue())) {
            // 领取挂机奖励
            String result = player.getModule(KowloonModule.class).getIncomeAward();
            kowLoonAwardRespMsg.setRet(0);
            kowLoonAwardRespMsg.setReward(result);
        } else {
            kowLoonAwardRespMsg.setRet(GameErrorCode.E_SYSTEM_NO_OPEN);
        }
        builder.setAssistantKowLoonAwardRespMsg(kowLoonAwardRespMsg);
    }

    /**
     * 领取日常任务奖励
     */
    private static void doDailyTaskAward(AssistantProto.AssistantActionRespMsg.Builder builder, GamePlayer player) {
        AssistantProto.AssistantDailyTaskRespMsg.Builder dailyTaskRespMsg = AssistantProto.AssistantDailyTaskRespMsg.newBuilder();
        if (SystemOpenMgr.systemOpen(player, eSystemId.DailyTask.getValue())) {
            //只做回包 不做进背包的奖励
            Property justRespReward = new Property();
            List<Integer> taskIdList = new ArrayList<>();
            // 日常任务
            TaskModule module = player.getModule(TaskModule.class);
            Map<Integer, BaseTaskData> baseTaskDataMap = module.getBaseTaskDataMap();
            module.startChanges();
            for (BaseTaskData baseTaskData : baseTaskDataMap.values()) {
                UserTaskData userTaskData = baseTaskData.getUserTaskData();
                if (userTaskData == null || userTaskData.getTaskType() != eTaskType.Daily.getValue()) {
                    continue;
                }
                int taskId = userTaskData.getTaskId();
                //获取任务信息
                TaskInfo taskInfo = TaskMgr.getTaskInfoById(taskId);
                if(null == taskInfo){
                    logger.error("任务id{}没有找到taskinfo",taskId);
                    continue;
                }
                //已经完成过了
                if(baseTaskData.getUserTaskData().getState() == 1){
                    continue;
                }
                //不能完成
                if(!baseTaskData.canCompleted()) {
                   continue;
                }
                justRespReward.addProperty(taskInfo.getReward());
                taskIdList.add(taskId);
                baseTaskData.finish();
                player.getModule(AttributeModule.class).addAttribute(ePlayerAttrType.TotalDailyTaskFinishTimes, 1);
            }
            module.finishChanges();
            //更新日常任务累计完成次数
            player.notifyListener(eGamePlayerEventType.DailyTaskTotalFinishTimes.getValue(), player.getModule(AttributeModule.class).getAttribute(ePlayerAttrType.TotalDailyTaskFinishTimes));

            // 活跃度任务
            UserTaskActive userTaskActive = module.getUserTaskActive();
            // 已经领取的列表
            List<Integer> awardIndexList = userTaskActive.getTaskGetRewardIndexList();
            List<Integer> configIndexList = ConfigMgr.getTaskDailyActiveList();
            for(Integer act:configIndexList) {
                //玩家身上的活跃度要大于配置的这一个配置的档位
                if (userTaskActive.getTaskActive() >= act && !awardIndexList.contains(act)) {
                    int index = ConfigMgr.getTaskDailyActiveIndex(act);
                    Property reward = ConfigMgr.getTaskDailyActiveReward(index);
                    justRespReward.addProperty(reward);
                    player.getModule(CurrencyModule.class).addCurrency(reward, eLogMoneyType.Task, eLogMoneyType.TaskGetDailyActiveReward);
                    userTaskActive.addRewadIndex(act);
                    LogMgr.addLogTaskActiveReward(player.getUserId(), act, index, PropertyHelper.parsePropertyToString(reward), false);
                }
            }
            module.syncTaskActive();
            dailyTaskRespMsg.setRet(0);
            dailyTaskRespMsg.setReward(PropertyHelper.parsePropertyToString(justRespReward));
            dailyTaskRespMsg.addAllTaskIdList(taskIdList);
        } else {
            dailyTaskRespMsg.setRet(GameErrorCode.E_SYSTEM_NO_OPEN);
        }
        builder.setAssistantDailyTaskRespMsg(dailyTaskRespMsg);
    }

    /**
     * 领取限时任务奖励
     */
    private static void doActLimitTaskAward(AssistantProto.AssistantActionRespMsg.Builder builder, GamePlayer player) {
        AssistantProto.AssistantActLimitTaskRespMsg.Builder limitTaskRespMsg = AssistantProto.AssistantActLimitTaskRespMsg.newBuilder();
        Property award = new Property();
        List<Integer> taskIdList = new ArrayList<>();
        if (SystemOpenMgr.systemOpen(player, eSystemId.TaskActivity.getValue())) {
            // 限时活动
            for (ActivityInfo actInfo:NormalActivityMgr.getShowTimeActivityInfoMap().values()){
                if(actInfo.getType() == eActivityType.TaskActivity.getValue()){
                    ActivityRewardResult result = player.getModule(ActivityModule.class).getAllActivityReward(actInfo.getActivityId());
                    award.addProperty(PropertyHelper.parseStringToProperty(result.getReward()));
                    taskIdList.addAll(result.getConditionIdList());
                }
            }
            limitTaskRespMsg.setRet(0);
            limitTaskRespMsg.setReward(PropertyHelper.parsePropertyToString(award));
            limitTaskRespMsg.addAllTaskIdList(taskIdList);
        } else {
            limitTaskRespMsg.setRet(GameErrorCode.E_SYSTEM_NO_OPEN);
        }
        builder.setAssistantActLimitTaskRespMsg(limitTaskRespMsg);
    }

    /**
     * 小玉自动看广告的奖励
     */
    public static void doAssistantWatchAdAward(AssistantProto.AssistantActionRespMsg.Builder builder, GamePlayer player,int systemId,int param){
        // 满足前提：该服务器存在广告活动
        ActivityInfo activityInfo = AdvertisementActivityMgr.getActivityInfo();
        AdvertisementConfig config = AdvertisementActivityMgr.getConfig();
        AdvertisementUserData userData = player.getModule(AdvertisementActivityModule.class).getUserData();
        if(activityInfo == null || config == null || userData == null){
            return;
        }
        // 满足前提：年卡用户
        if (!player.getModule(CardModule.class).isInCardTime(eCardType.YearCard.getValue())) {
            return;
        }
        //保守遍历个100次 运营如果一天让玩家看一百次我没话说
        for (int i = 0; i < 100; i++) {
            AdvertisementProto.WatchAdvertisementOverRespMsg.Builder watchAdOver = null;
            if (systemId == eAdvertisementSystemId.travel.getValue()){
                watchAdOver = player.getModule(AdvertisementActivityModule.class).assistantWatchAdTravel(activityInfo.getActivityId(),param);

            } else if (systemId == eAdvertisementSystemId.lottery.getValue()){
                watchAdOver = player.getModule(AdvertisementActivityModule.class).watchAdOver(activityInfo.getActivityId(), systemId, System.currentTimeMillis(), 1, 0);

            }else if (systemId == eAdvertisementSystemId.buildingNpc.getValue()){
                watchAdOver = player.getModule(AdvertisementActivityModule.class).watchAdOver(activityInfo.getActivityId(), systemId, System.currentTimeMillis(), 1, 0);

            }else if (systemId == eAdvertisementSystemId.addEarnSpeed.getValue()){
                watchAdOver = player.getModule(AdvertisementActivityModule.class).watchAdOver(activityInfo.getActivityId(), systemId, System.currentTimeMillis(), 1, 0);

            }else if (systemId == eAdvertisementSystemId.washe.getValue()){
                watchAdOver = player.getModule(AdvertisementActivityModule.class).watchAdOver(activityInfo.getActivityId(), systemId, System.currentTimeMillis(), 1, 0);

            }else if (systemId == eAdvertisementSystemId.Login.getValue()){
                watchAdOver = player.getModule(AdvertisementActivityModule.class).watchAdOver(activityInfo.getActivityId(), systemId, System.currentTimeMillis(), 1, 0);
            }
            //如果空了 不给传好了
            if (watchAdOver == null){
                break;
            }
            //如果错误码已经不是0了 就跳出循环
            if (watchAdOver.getRet() != 0){

                if (systemId == eAdvertisementSystemId.travel.getValue()){
                    //如果当前回包为空
                    if (!builder.hasAdTravelRespMsg()){
                        //就把回包给他
                        builder.setAdTravelRespMsg(watchAdOver);
                    }

                } else if (systemId == eAdvertisementSystemId.lottery.getValue()){
                    if (!builder.hasAdLotteryRespMsg()){
                        builder.setAdLotteryRespMsg(watchAdOver);
                    }

                }else if (systemId == eAdvertisementSystemId.buildingNpc.getValue()){
                    if (!builder.hasAdNpcRespMsg()){
                        builder.setAdNpcRespMsg(watchAdOver);
                    }

                }else if (systemId == eAdvertisementSystemId.addEarnSpeed.getValue()){
                    if (!builder.hasAdEarnSpeedRespMsg()){
                        builder.setAdEarnSpeedRespMsg(watchAdOver);
                    }

                }else if (systemId == eAdvertisementSystemId.washe.getValue()){
                    if (!builder.hasAdWaSheDailyRespMsg()){
                        builder.setAdWaSheDailyRespMsg(watchAdOver);
                    }
                }else if (systemId == eAdvertisementSystemId.Login.getValue()){
                    if (!builder.hasAdLoginDailyRespMsg()){
                        builder.setAdLoginDailyRespMsg(watchAdOver);
                    }
                }

                //不为空的就把成功的弹出去
                break;
            }else {

                if (systemId == eAdvertisementSystemId.travel.getValue()){
                    //如果当前回包为空
                    if (!builder.hasAdTravelRespMsg()){
                        //就把回包给他
                        builder.setAdTravelRespMsg(watchAdOver);
                        continue;
                    }else {
                        //合并上一次的结果和这一次的结果
                        AdvertisementProto.WatchAdvertisementOverRespMsg.Builder mergeAdvertisementRespMsg = AdvertisementActivityMgr.mergeAssistAdvertisementRespMsg(builder.getAdTravelRespMsgBuilder(), watchAdOver);
                        //如果不为空就赋值
                        if (mergeAdvertisementRespMsg != null){
                            builder.setAdTravelRespMsg(mergeAdvertisementRespMsg);
                        }
                    }
                } else if (systemId == eAdvertisementSystemId.lottery.getValue()){
                    if (!builder.hasAdLotteryRespMsg()){
                        builder.setAdLotteryRespMsg(watchAdOver);
                        continue;
                    }else {
                        AdvertisementProto.WatchAdvertisementOverRespMsg.Builder mergeAdvertisementRespMsg = AdvertisementActivityMgr.mergeAssistAdvertisementRespMsg(builder.getAdLotteryRespMsgBuilder(), watchAdOver);
                        if (mergeAdvertisementRespMsg != null){
                            builder.setAdLotteryRespMsg(mergeAdvertisementRespMsg);
                        }
                    }

                }else if (systemId == eAdvertisementSystemId.buildingNpc.getValue()){
                    if (!builder.hasAdNpcRespMsg()){
                        builder.setAdNpcRespMsg(watchAdOver);
                        continue;
                    }else {
                        AdvertisementProto.WatchAdvertisementOverRespMsg.Builder mergeAdvertisementRespMsg = AdvertisementActivityMgr.mergeAssistAdvertisementRespMsg(builder.getAdNpcRespMsgBuilder(), watchAdOver);
                        if (mergeAdvertisementRespMsg != null){
                            builder.setAdNpcRespMsg(mergeAdvertisementRespMsg);
                        }
                    }

                }else if (systemId == eAdvertisementSystemId.addEarnSpeed.getValue()){
                    if (!builder.hasAdEarnSpeedRespMsg()){
                        builder.setAdEarnSpeedRespMsg(watchAdOver);
                        continue;
                    }else {
                        AdvertisementProto.WatchAdvertisementOverRespMsg.Builder mergeAdvertisementRespMsg = AdvertisementActivityMgr.mergeAssistAdvertisementRespMsg(builder.getAdEarnSpeedRespMsgBuilder(), watchAdOver);
                        if (mergeAdvertisementRespMsg != null){
                            builder.setAdEarnSpeedRespMsg(mergeAdvertisementRespMsg);
                        }
                    }
                }else if (systemId == eAdvertisementSystemId.washe.getValue()){
                    if (!builder.hasAdWaSheDailyRespMsg()){
                        builder.setAdWaSheDailyRespMsg(watchAdOver);
                        continue;
                    } else {
                        AdvertisementProto.WatchAdvertisementOverRespMsg.Builder mergeAdvertisementRespMsg = AdvertisementActivityMgr.mergeAssistAdvertisementRespMsg(builder.getAdWaSheDailyRespMsgBuilder(), watchAdOver);
                        if (mergeAdvertisementRespMsg != null){
                            builder.setAdWaSheDailyRespMsg(mergeAdvertisementRespMsg);
                        }
                    }
                }else if (systemId == eAdvertisementSystemId.Login.getValue()){
                    if (!builder.hasAdLoginDailyRespMsg()){
                        builder.setAdLoginDailyRespMsg(watchAdOver);
                        continue;
                    }else {
                        AdvertisementProto.WatchAdvertisementOverRespMsg.Builder mergeAdvertisementRespMsg = AdvertisementActivityMgr.mergeAssistAdvertisementRespMsg(builder.getAdLoginDailyRespMsgBuilder(), watchAdOver);
                        if (mergeAdvertisementRespMsg != null){
                            builder.setAdLoginDailyRespMsg(mergeAdvertisementRespMsg);
                        }
                    }
                }


            }
        }
    }


    /**
     * 观影有奖礼包商店自动购买
     */
    private static void doAdShopBuyAward(AssistantProto.AssistantActionRespMsg.Builder builder, GamePlayer player){
        AssistantProto.AssistantAdShopBuyRespMsg.Builder adShopBuyBuilder = AssistantProto.AssistantAdShopBuyRespMsg.newBuilder();
        Property award = new Property();
        // 满足前提：年卡用户
        if (!player.getModule(CardModule.class).isInCardTime(eCardType.YearCard.getValue())) {
            return;
        }
        // 满足前提：该服务器存在广告活动
        ActivityInfo activityInfo = AdvertisementActivityMgr.getActivityInfo();
        AdvertisementConfig config = AdvertisementActivityMgr.getConfig();
        AdvertisementUserData userData = player.getModule(AdvertisementActivityModule.class).getUserData();
        if(activityInfo == null || config == null || userData == null){
            return;
        }
        // 满足前提：广告活动存在商城220
        if(!userData.getSystemDataMap().containsKey(eAdvertisementSystemId.ingotMall.getValue())){
            return;
        }
        MallActivityInfo inTimeActivity = MallActivityMgr.getInTimeActivity(activityInfo.getActivityId());
        if (inTimeActivity == null){
            return;
        }
        for (MallInfo mall : inTimeActivity.getMallInfoMap().values()) {
            //如果不是免费礼包就不鸟他
            if (mall.getShopType() != eShopType.AdvertisementFreeMall.getValue() && mall.getShopType() != eShopType.AdvertisementFreeNoWatchMall.getValue()){
                continue;
            }
            int count = mall.getLimitBuyCount();
            //6.4修复 由于免费购买且不需要看的礼包 客户端与服务端使用购买协议不同 导致出现两个限购数据同步 一个是商城的一个是活动的 以后用商店购买同步增加活动的购买次数与判断
            if (mall.getShopType() == eShopType.AdvertisementFreeNoWatchMall.getValue()){
                int mallId = mall.getMallId();
                ReturnData returnData = player.getModule(MallModule.class).preBuyGoods(mallId, count);
                int ret = returnData.getRet();
                if (ret != 0){
                    continue;
                }
                //这个商店都是免费的 以防万一把消耗抄过来
                Property consume = PropertyHelper.parseStringToProperty(returnData.getParams().get(0));
                //先看看这个商店要不要扣道具
                if (player.getModule(CurrencyModule.class).removeCurrency(consume, eLogMoneyType.Mall, eLogMoneyType.MallBuy, mallId + ":" + count)) {
                    String reward = player.getModule(MallModule.class).buyGoods(mallId, count);
                    award.addProperty(PropertyHelper.parseStringToProperty(reward));
                    MallInfo mallInfo = MallMgr.getMallInfoByMallId(mallId);
                    BuyItemLog.trackShopBuyItemSingle(player, new BuyShopItem(mallInfo, count, consume, PropertyHelper.parseStringToProperty(reward))) ;
                } else {
                    //不是免费的并且没有道具了 下一个
                    continue;
                }
                //无论什么结果 直接下一个
                continue;
            }

            BuyGoodsResult buyGoodsResult = player.getModule(ActivityMallModule.class).buyGoods(mall, count);
            if (buyGoodsResult.getRet() == 0) {
                award.addProperty(PropertyHelper.parseStringToProperty(buyGoodsResult.getReward()));
                //成就活动没过期的话加成就
                if (SystemOpenMgr.systemOpen(player,eSystemId.Advertisement.getValue())){
                    if (player.getTitleId() >= config.getTotalWatchMinLevel()){
                        if (userData.getActiveTime() + config.getTotalWatchRewardActiveDay() * DateHelper.DAY_MILLIONS >= System.currentTimeMillis()){
                            player.notifyListener(eGamePlayerEventType.TotalWatchAdvertisementTimeCondition.getValue());
                        }
                    }
                }
                player.notifyListener(eGamePlayerEventType.AdvertisementDailyResetCondition.getValue());
            }
        }

        //拿出所有有商城的活动 不想拿但是策划要 很烦
        List<MallActivityInfo> inTimeActivityList = MallActivityMgr.getInTimeActivityList();
        for (MallActivityInfo mallActivityInfo:inTimeActivityList){
            //广告已经处理过的活动id就跳过 不要重新处理
            if (mallActivityInfo.getActivityId() == activityInfo.getActivityId()){
                continue;
            }
            Map<Integer, MallInfo> mallInfoMap = mallActivityInfo.getMallInfoMap();
            for (MallInfo mall:mallInfoMap.values()){
                //其他活动的商城只要配这个类型的 这个要看广告的
                if (mall.getShopType() != eShopType.AdvertisementFreeMall.getValue()){
                    continue;
                }
                int count = mall.getLimitBuyCount();
                BuyGoodsResult buyGoodsResult = player.getModule(ActivityMallModule.class).buyGoods(mall, count);
                if (buyGoodsResult.getRet() == 0) {
                    award.addProperty(PropertyHelper.parseStringToProperty(buyGoodsResult.getReward()));
                    //成就活动没过期的话加成就
                    if (SystemOpenMgr.systemOpen(player,eSystemId.Advertisement.getValue())){
                        if (player.getTitleId() >= config.getTotalWatchMinLevel()){
                            if (userData.getActiveTime() + config.getTotalWatchRewardActiveDay() * DateHelper.DAY_MILLIONS >= System.currentTimeMillis()){
                                player.notifyListener(eGamePlayerEventType.TotalWatchAdvertisementTimeCondition.getValue());
                            }
                        }
                    }
                    player.notifyListener(eGamePlayerEventType.AdvertisementDailyResetCondition.getValue());
                }
            }
        }

        adShopBuyBuilder.setRet(0);
        adShopBuyBuilder.setReward(PropertyHelper.parsePropertyToString(award));
        builder.setAssistantAdShopBuyRespMsg(adShopBuyBuilder);
    }

    /**
     * 招商操作
     */
    public static int zsAction(GamePlayer player, AssistantProto.AssistantActionReqMsg.Builder reqMsg, AssistantProto.AssistantActionRespMsg.Builder respMsg) {
        if (!player.getModule(ZsModule.class).isZsSystemOpen()) {
            return GameErrorCode.E_SYSTEM_NO_OPEN;
        }

        AssistantProto.AssistantCrossActionReqMsg.Builder crossMsg = AssistantProto.AssistantCrossActionReqMsg.newBuilder();
        crossMsg.setAssistantActionReqMsg(reqMsg);
        crossMsg.setAssistantActionRespMsg(respMsg);

        List<Integer> zsTypeList = player.getModule(AssistantModule.class).getZsTypeList();
        if (zsTypeList.isEmpty()) {
            return GameErrorCode.E_ZS_PROJECT_NO_AUTO_SET;
        }
        //按照vip等级获取项目开启倍数
        int limitMultiple = player.getModule(ZsModule.class).getLimitMultiple();

        int zsOpenNum = player.getModule(ZsModule.class).getZsOpenNum();

        Property totalCost = new Property();

        CurrencyModule currencyModule = player.getModule(CurrencyModule.class);

        AssistantProto.CrossAssistantZsProjectOpenReqMsg.Builder zsCrossReqMsg = AssistantProto.CrossAssistantZsProjectOpenReqMsg.newBuilder();
        for (Integer zsType : zsTypeList) {
            ZsProjectInfo zsProjectInfo = ZsConfigMgr.getByType(zsType);
            if (zsProjectInfo == null) {
                continue;
            }

            while (zsOpenNum > 0) {
                int num = 0;//实际使用次数
                for (int i = 0; i < limitMultiple; i++) {
                    Property oneCost = PropertyHelper.parseStringToProperty(zsProjectInfo.getConsume());//1次的消耗
                    Property checkCost = new Property(totalCost);
                    checkCost.addProperty(oneCost);
                    if (!currencyModule.currencyIsEnough(checkCost)) {
                        break;
                    }
                    totalCost.addProperty(oneCost);
                    num++;
                }

                if (num == 0) {
                    break;
                }

                ZhaoShangProto.ZsProjectOpenReqMsg.Builder openInfo = ZhaoShangProto.ZsProjectOpenReqMsg.newBuilder();
                openInfo.setNum(num);
                openInfo.setTemplateId(zsProjectInfo.getId());
                zsCrossReqMsg.addOpenInfo(openInfo);

                zsOpenNum--;
            }

            if (zsOpenNum <= 0) {
                break;
            }
        }

        if (zsCrossReqMsg.getOpenInfoCount() == 0) {
            return GameErrorCode.E_ZS_PROJECT_NO_AUTO_SET;
        }

        //消耗判断
        if (!player.getModule(CurrencyModule.class).currencyIsEnough(totalCost)) {
            return GameErrorCode.E_BAG_ITEM_NO_ENOUGH;
        }

        player.getModule(PreReduceModule.class).preReduce(PropertyHelper.parsePropertyToString(totalCost));


        //userBaseInfo在前，检测下装饰过期
        UserBaseInfo userBaseInfo = UserMgr.parseUserBaseInfo(player.getUserInfo(), GameServer.getInstance().getServerId());
        UserDecorationInfoResult result = player.getModule(DecorationModule.class).getCurMaxDecorationInfo();
        int decorationId = result.decorationId;
        long decorationOverTime = result.decorationOverTime;
        //称号加成
        int decorationAddition = ZsMgr.getDecorationAddition(decorationId);

        zsCrossReqMsg.setPlayerBaseData(PlayerBasePb.parsePlayerBaseTempMsg(userBaseInfo));
        zsCrossReqMsg.setAddition(decorationAddition);
        zsCrossReqMsg.setTitleAddition(ZsMgr.getTitleAddition(player.getTitleId()));
        zsCrossReqMsg.setOpenNumLimit(player.getModule(ZsModule.class).getZsOpenNum());
        zsCrossReqMsg.setGroupId(ZsMgr.getGroupId(GameServer.getInstance().getServerId()));  //分组id
        zsCrossReqMsg.setDecorationOverTime(decorationOverTime);
        zsCrossReqMsg.setSkillAddition((int) CurioMgr.getSkillAdditionBySkillType(eSkillType.CurioZSTokenSkill.getValue(), player, 0));
        //开启时间限制
        zsCrossReqMsg.addTimeLimit(ConfigMgr.getZsProjectOpenTime().get(0));
        zsCrossReqMsg.addTimeLimit(ConfigMgr.getZsProjectOpenTime().get(1));
        zsCrossReqMsg.setPreCost(totalCost.toHelperString());

        crossMsg.setZsReqMsg(zsCrossReqMsg);

        player.sendPacket(CrossProtocol.C_ZS_ASSISTANT_ACTION, crossMsg);

        return 0;

    }
}
